﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.Electric;
using YArchitech.LIB;

namespace HYRElectric.SystemDiagram
{
	public partial class SwitchTagForm : System.Windows.Forms.Form
	{
		public SwitchTagForm(SystemCreateForm form, List<string> lstTag)
		{
			this.InitializeComponent();
			this.m_parent = form;
			for (int i = 0; i < lstTag.Count<string>(); i++)
			{
				this.m_lstTag.Add(lstTag[i]);
			}
			this.InitTagList();
			this.toolTip1.SetToolTip(this.btnAdd, "添加标注");
			this.toolTip1.SetToolTip(this.btnDelete, "删除标注");
		}

		private void InitTagList()
		{
			this.lvwSwitchTag.Items.Clear();
			foreach (string text in this.m_lstTag)
			{
				this.lvwSwitchTag.Items.Add(text);
			}
			if (this.lvwSwitchTag.Items.Count > 0)
			{
				this.txtTag.Text = this.lvwSwitchTag.Items[0].Text;
				this.lvwSwitchTag.Items[0].Selected = true;
				return;
			}
			this.txtTag.Text = "";
		}

		private void btnAdd_Click(object sender, EventArgs e)
		{
			string text = this.txtTag.Text;
			if (text != string.Empty && !this.m_lstTag.Contains(text))
			{
				this.m_lstTag.Add(this.txtTag.Text);
				this.InitTagList();
			}
		}

		private void btnDelete_Click(object sender, EventArgs e)
		{
			string text = this.txtTag.Text;
			if (text != string.Empty && this.m_lstTag.Contains(text))
			{
				this.m_lstTag.Remove(this.txtTag.Text);
				this.InitTagList();
			}
		}

		private void btnSelect_Click(object sender, EventArgs e)
		{
			if (this.lvwSwitchTag.SelectedItems.Count <= 0)
			{
				YJKMessageBox.Show("无标注内容");
				return;
			}
			this.m_parent.SetTagText(this.lvwSwitchTag.SelectedItems[0].Text);
			this.m_parent.SaveTage(this.m_lstTag);
			base.Close();
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			this.m_parent.SaveTage(this.m_lstTag);
			base.Close();
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void SwitchTagForm_Load(object sender, EventArgs e)
		{
			this.btnAdd.Image = YArchitech.Electric.Resources.GetImage("Add20");
			this.btnDelete.Image = YArchitech.Electric.Resources.GetImage("Delete20");
			//base.Icon = Resource.YArchitechIcon;
		}

		private void lvwSwitchTag_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.lvwSwitchTag.SelectedItems.Count <= 0)
			{
				return;
			}
			this.txtTag.Text = this.lvwSwitchTag.SelectedItems[0].Text;
		}

		private List<string> m_lstTag = new List<string>();

		private SystemCreateForm m_parent;
	}
}
